<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>借阅记录列表</title>
    <style>
        input[type="submit"],.button-link {
            width: 100%;
            padding: 10px;
            border: none;
            border-radius: 4px;
            background-color: #4CAF50;
            color: white;
            cursor: pointer;
            text-decoration: none;
            display: inline-block;
            text-align: center;
        }

        input[type="submit"]:hover,.button-link:hover {
            background-color: #45a049;
        }

        .button-container {
            text-align: center;
            margin-top: 15px;
        }

        body, html {
            height: 100%;
            margin: 0;
            font-family: Arial, sans-serif;
        }

        .sidebar {
            width: 90px;
            background-color: #333;
            color: white;
            padding: 15px;
            position: fixed;
            top: 0;
            left: 0;
            height: 100%;
        }

        .sidebar h2 {
            padding: 10px;
            color: #fff;
        }

        .sidebar ul {
            list-style-type: none;
            padding: 0;
        }

        .sidebar ul li a {
            color: white;
            padding: 10px;
            display: block;
            text-decoration: none;
        }

        .sidebar ul li a:hover {
            background-color: #575757;
        }

        .sidebar ul li a.active {
            background-color: #4CAF50; /* 设置当前页面的背景颜色 */
        }

        .main-content {
            margin-left: 120px;
            padding: 20px;
        }

        .header {
            background-color: #333;
            color: white;
            text-align: center;
            padding: 10px 0;
        }

        .content {
            padding: 20px;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }

        th, td {
            border: 1px solid #ddd;
            padding: 8px;
            text-align: left;
        }

        th {
            background-color: #f2f2f2;
        }
    </style>
</head>
<body>
<div class="sidebar">
    <h2>菜单</h2>
    <ul>
        <li><a href="bookList.jsp" class="<%= request.getRequestURI().endsWith("bookList.jsp")? "active" : "" %>">图书列表</a></li>
        <li><a href="addBook.jsp" class="<%= request.getRequestURI().endsWith("addBook.jsp")? "active" : "" %>">添加图书</a></li>
        <li><a href="borrowRecord.jsp" class="<%= request.getRequestURI().endsWith("borrowRecord.jsp")? "active" : "" %>">借阅记录</a></li>
        <li><a href="readerList.jsp" class="<%= request.getRequestURI().endsWith("readerList.jsp")? "active" : "" %>">读者列表</a></li>
        <li id="adminLink" style="display: none;"><a href="bookManagement.jsp" class="<%= request.getRequestURI().endsWith("bookManagement.jsp")? "active" : "" %>">管理入口</a></li>
        <li><a href="PersonalData.jsp" class="<%= request.getRequestURI().endsWith("PersonalData.jsp")? "active" : "" %>">个人中心</a></li>
        <li><a href="<%=request.getContextPath()%>/login.jsp">退出登录</a></li>
    </ul>
</div>
<div class="main-content">
    <div class="header">
        <a>图书信息管理系统 - 借阅记录列表</a>
    </div>
    <div class="content">
        <h2>借阅记录列表</h2>
        <table>
            <thead>
            <tr>
                <th>记录ID</th>
                <th>用户ID</th>
                <th>图书ID</th>
                <th>借阅日期</th>
                <th>归还日期</th>
                <th>是否归还</th>
            </tr>
            </thead>
            <tbody>
            <%@ page import="com.wzu.pojo.BorrowRecord" %>
            <%@ page import="com.wzu.service.BorrowRecordService" %>
            <%@ page import="com.wzu.service.BorrowRecordServiceImpl" %>
            <%
                BorrowRecordService borrowRecordService = new BorrowRecordServiceImpl();
                java.util.List<BorrowRecord> borrowRecordList = borrowRecordService.getAllBorrowRecords();
                for (BorrowRecord record : borrowRecordList) {
            %>
            <tr>
                <td><%= record.getRecord_id() %></td>
                <td><%= record.getUser_id() %></td>
                <td><%= record.getBook_id() %></td>
                <td><%= record.getBorrow_date() %></td>
                <td><%= record.getReturn_date() %></td>
                <td><%= record.isIs_returned()? "是" : "否" %></td>
            </tr>
            <%
                }
            %>
            </tbody>
        </table>
    </div>
</div>
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
<script>
    // 读取信息
    let userInfo = sessionStorage.getItem('userInfo');
    userInfo = userInfo? JSON.parse(userInfo) : null;
    console.log(userInfo);

    // 根据 isroot 的值动态显示/隐藏 "管理入口"
    if (userInfo && userInfo.isroot === 0) {
        document.getElementById('adminLink').style.display = 'none';
    } else {
        document.getElementById('adminLink').style.display = 'list-item';
    }
</script>
</body>
</html>